package com.cbg.sys.utils;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cbg.base.constant.Constant;
import com.cbg.base.utils.SpringContextHolder;
import com.cbg.sys.entity.Line;
import com.cbg.sys.entity.SeatPrice;
import com.cbg.sys.service.ILineService;
import com.cbg.sys.service.ISeatPriceService;
import java.math.BigDecimal;

/**
 * <pre></pre>
 * <small> 2018-12-18 | chenbing </small>
 */
public class PriceUtils {
    private static long msec(String x){
        return DateUtil.parse(x, Constant.FORMAT).getTime();
    }

    public static SeatPrice esurePriceByLineId(String lineId,String typeId){
        Line line = SpringContextHolder.getBean(ILineService.class).getById(lineId);
        return SpringContextHolder.getBean(ISeatPriceService.class)
                .getOne(new LambdaQueryWrapper<SeatPrice>().eq(SeatPrice::getTypeId,typeId)
                .le(SeatPrice::getHeadMsec,msec(line.getGoTimeHead()))
                .ge(SeatPrice::getTailMsec,msec(line.getGoTimeTail())));
    }

    public static BigDecimal esurePriceBySeatId(int x, SeatPrice seatPrice) {
        System.err.println(x);
        System.err.println(seatPrice);
        switch (x) {
            case 0:
                return seatPrice.getOneWorth();
            case 1:
                return seatPrice.getTwoWorth();
            case 2:
                return seatPrice.getThreeWorth();
            case 3:
                return seatPrice.getFourWorth();
            case 4:
                return seatPrice.getFiveWorth();
            case 5:
                return seatPrice.getSixWorth();
            default:
                return new BigDecimal(0);
        }
    }
}
